<template>
	<div class="page">
		<c-title :hide="false" text="添加血糖记录"></c-title>
		<van-field v-model="lc" label="凌晨" placeholder="凌晨" />
		<van-field v-model="kf" label="空腹" placeholder="空腹" />
		<van-field v-model="zch" label="早餐后" placeholder="早餐后" />
		<van-field v-model="wcq" label="午餐前" placeholder="午餐前" />
		<van-field v-model="wch" label="午餐后" placeholder="午餐后" />
		<van-field v-model="wanq" label="晚餐前" placeholder="晚餐前" />
		<van-field v-model="wanh" label="晚餐后" placeholder="晚餐后" />
		<van-field v-model="sq" label="睡前" placeholder="睡前" />
		<van-field @click=" pickerShow = true" v-model="time" label="时间" placeholder="请输入时间" />

		<van-popup v-model="pickerShow" :close-on-click-overlay="false" position="bottom">
			<van-datetime-picker type="date" title="选择年月日" v-model="pickerValue" @cancel="pickerShow = false"
			 @confirm="setDate" />
		</van-popup>
		<div class="submit" @click="submit">提交</div>
	</div>
</template>

<script>
	import {
		Toast
	} from 'vant';
	export default {
		data() {
			return {
				lc: '',
				kf: '',
				zch: '',
				wcq: '',
				wch: '',
				wanq: '',
				wanh: '',
				sq: '',
				time: '',
				pickerShow: false,
				pickerValue: new Date(),
			}
		},
		methods: {
			submit() {
				$http
					.post("plugin.hft-hospital.api.jiankang.subimit-xuetang-data", {
						lingchen: this.lc,
						kongfu: this.kf,
						zaocanhou: this.zch,
						wucanqian: this.wcq,
						wucanhou: this.wch,
						wancanqian: this.wanq,
						wancanhou: this.wanh,
						shuiqian: this.sq,
						time: this.time
					})
					.then(response => {
						console.log(response)
						if (response.result === 1) {
							Toast('添加成功！')
							this.$router.go(-1);
						} else {
							Toast(response.msg);
						}
					})
					.catch(error => {
						console.log(error);
					});
			},
			setDate(ret) {

				this.time = ret.Format("yyyy-MM-dd");

				this.pickerShow = false;
			},
		}
	}
</script>

<style scoped lang="scss">
	.submit {
		position: fixed;
		bottom: 0;
		width: 100%;
		line-height: 2rem;
		color: #fff;
		background-color: #169BD5;
	}
</style>
